package de.andreavicentini.teatralia.pages.events;

import java.util.ArrayList;
import java.util.List;

import de.andreavicentini.teatralia.pages.ObjectListModel;
import de.andreavicentini.teatralia.pages.TDate;
import de.andreavicentini.teatralia.pages.repertoire.PlaysModel;



public class EventsModel extends ObjectListModel<Event>{

	
	public EventsModel(PlaysModel plays) {
		Location dreigroschen = new Location("Dreigroschentheater, Kolbstr. 4c, 70199 Stuttgart", "http://maps.google.de/maps?f=q&source=s_q&hl=de&geocode=&q=Dreigroschentheater,+Kolbstr.+4c,+Stuttgart&sll=51.151786,10.415039&sspn=14.132112,25.883789&ie=UTF8&z=16");
		Location vhs = new Location("VHS - Clara Blum Saal, Fritz-Elsas-str. 46/48, 70174 Stuttgart", "http://maps.google.de/maps?oe=utf-8&client=firefox-a&ie=UTF8&q=volkshochschule+stuttgart&fb=1&split=1&gl=de&ei=dqawSo6FJof-_AbBgoyLDA&hl=de&sll=48.791432,9.191292&sspn=0.029073,0.059065&sig2=Eg3nkVcEEqEEWZQKGgnWFA&cd=2&usq=volkshochschule+stuttgart&geocode=Fb9G6AIdoOiLAA&cid=15107998415752627594&li=lmd&ll=48.77804,9.169056&spn=0.00724,0.012639&z=16");
		Location uni_k4 = new Location("Universität K4, Geschwister-Scholl-Straße 24D, 70174 Stuttgart", "http://maps.google.de/maps?f=q&source=s_q&hl=de&geocode=&q=Geschwister-Scholl-Stra%C3%9Fe+24D,+70174+Stuttgart&sll=48.788997,9.175043&sspn=0.028953,0.050554&ie=UTF8&ll=48.783173,9.176137&spn=0.007239,0.012639&z=16");
		Location arces = new Location("ARCES Corsari e.V., Lohäckerstraße 11, 70567 Stuttgart", "http://maps.google.com/maps?f=q&source=s_q&hl=de&geocode=&q=Loh%C3%A4ckerstra%C3%9Fe+11+70567+Stuttgart&sll=48.777106,9.180769&sspn=0.314482,0.669479&ie=UTF8&hq=&hnear=Loh%C3%A4ckerstra%C3%9Fe+11,+Stuttgart+70567+Stuttgart,+Baden-W%C3%BCrttemberg,+Deutschland&z=16&iwloc=r0");
		
		this.add(new Event(plays.tre_atti_unici, new TDate(2009, 9, 26, 20, 00), dreigroschen, "http://www.flickr.com/photos/mrmagixx/sets/72157622424848111/show"));
		this.add(new Event(plays.tre_atti_unici, new TDate(2009, 10, 23, 20, 00), vhs));
		this.add(new Event(plays.in_viaggio, new TDate(2009, 11, 27, 20, 00), uni_k4, "http://www.flickr.com/photos/mrmagixx/sets/72157622893674294/show"));
		this.add(new Event(plays.recita_a_soggetto, new TDate(2010, 11, 12, 20, 00), uni_k4));
		this.add(new Event(plays.recita_a_soggetto, new TDate(2010, 11, 20, 20, 00), dreigroschen));
		this.add(new Event(plays.recita_a_soggetto, new TDate(2010, 12, 10, 20, 00), arces));
	}
	
	public Iterable<Event> listPastEvents() {
		long currentTime = System.currentTimeMillis();
		List<Event> result = new ArrayList<Event>();
		for (Event event : this)
			if (event.getDate().getTime() < currentTime)
				result.add(event);
			else break;
		return result;
	}
	
	public Iterable<Event> listNextEvents() {
		long currentTime = System.currentTimeMillis();
		List<Event> result = new ArrayList<Event>();
		for (Event event : this)
			if (event.getDate().getTime() < currentTime)
				continue;
			else 
				result.add(event);
		return result;
	}
}
